program scoreboard;
const n:integer = 5;
var dname:array[1..n] of string[25];
    dres:array[1..n] of integer;
    dplace:array[1..n] of byte;

    i,j,k,l, m,tr,P:integer;
    tmp:string[100];
    str1:string[20];
    c:char;

begin
write('n=',n,'  enter m: ');
readln(m);

for i:=1 to n do dres[i]:=0;

FOR i:=1 TO n DO BEGIN
	j:=1;
	repeat
		read(c);
		dname[i]:=dname[i]+c;
		inc(j);
	until c=' ';
	delete(dname[i],j,1);
	dres[i]:=0;

	for l:=1 to m do begin
		str1:='';
		repeat
			read(c);
			str1:=str1+c;
			until c=' ';
		delete(str1,length(str1),1);

		tr:=0;
		for k:=1 to length(str1) do begin
			tr:=tr*10 + ord(str1[k]) - ord('0');
			end;
		dres[i]:=dres[i]+tr;
		end;
	END;

for i:=1 to n do begin
	for j:=i+1 to n do begin
		if dres[i]<dres[j] then begin
			tr:=dres[j];
			dres[j]:=dres[i];
			dres[i]:=tr;
			
			tmp:=dname[j];
			dname[j]:=dname[i];
			dname[i]:=tmp;
			end;
		end;
	end;

tr:=dres[1];
P:=1;

for i:=1 to n do if dres[i]<tr then begin
		inc(P);
		dplace[i]:=P;
		tr:=dres[i];
		end
	else dplace[i]:=P;

writeln;

for i:=1 to n do writeln(dplace[i]:2,dres[i]:5,' ',dname[i]);

end.
